# import numpy as np
# from scipy.ndimage import rotate
# import matplotlib.pyplot as plt
#
# # 假设你的多波段数据是通过 np.load 加载的
# def load_multiband_data(file_path):
#     return np.load(file_path)  # 读取 npy 文件
#
# # 对多波段影像进行旋转
# def rotate_multiband_image(bands, angle):
#     rotated_bands = []
#     for band in bands:
#         # 使用 scipy.ndimage.rotate 进行图像旋转
#         rotated_band = rotate(band, angle, reshape=True, mode='nearest', order=1)
#         rotated_bands.append(rotated_band)
#     return np.array(rotated_bands)
#
# # 显示某个波段图像
# def display_band_image(band):
#     plt.imshow(band, cmap='gray')
#     plt.colorbar()
#     plt.title("Rotated Band")
#     plt.show()
#
# # 主程序
# def main():
#     # 加载多波段影像数据
#     input_file = 'data/image/28.npy'  # 输入数据文件路径
#     bands = load_multiband_data(input_file)
#
#     # 设置旋转角度
#     angle = 135  # 旋转角度（可以根据需求修改）
#
#     # 进行旋转处理
#     rotated_bands = rotate_multiband_image(bands, angle)
#
#     # 可选：显示旋转后的某个波段图像
#     display_band_image(rotated_bands[0])  # 显示第一个波段（可根据需求选择波段）
#
# if __name__ == "__main__":
#     main()
import os

import numpy as np
from matplotlib import pyplot as plt
def compute_color_difference(img1, img2):
    # 确保图像形状相同
    if img1.shape != img2.shape:
        raise ValueError("Input images must have the same shape.")

    # 计算色差（欧几里得距离）
    color_diff = np.sqrt(np.sum((img1 - img2) ** 2, axis=-1))  # 计算每个像素的色差
    return color_diff
from rs_trasformer import *
name='28.npy'# md随便选了几张结果连分割图都没有，倒霉
x1=r'data\image'
x2=r'data\edge'
x3=r'data\mask'
input=os.path.join(x1,name)#4波段数据
edge=os.path.join(x2,name) #边缘线分割图
mask=os.path.join(x3,name) #地块分割图
do_band = 4
# import numpy as np
# from scipy.ndimage import rotate
# import matplotlib.pyplot as plt
#
# # 假设你的多波段数据是通过 np.load 加载的
# def load_multiband_data(file_path):
#     return np.load(file_path)  # 读取 npy 文件
#
# # 对多波段影像进行旋转
# def rotate_multiband_image(bands, angle):
#     rotated_bands = []
#     for band in bands:
#         # 使用 scipy.ndimage.rotate 进行图像旋转
#         rotated_band = rotate(band, angle, reshape=True, mode='nearest', order=1)
#         rotated_bands.append(rotated_band)
#     return np.array(rotated_bands)
#
# # 显示某个波段图像
# def display_band_image(band):
#     plt.imshow(band, cmap='gray')
#     plt.colorbar()
#     plt.title("Rotated Band")
#     plt.show()
#
# # 主程序
# def main():
#     # 加载多波段影像数据
#     input_file = 'data/image/28.npy'  # 输入数据文件路径
#     bands = load_multiband_data(input_file)
#
#     # 设置旋转角度
#     angle = 135  # 旋转角度（可以根据需求修改）
#
#     # 进行旋转处理
#     rotated_bands = rotate_multiband_image(bands, angle)
#
#     # 可选：显示旋转后的某个波段图像
#     display_band_image(rotated_bands[0])  # 显示第一个波段（可根据需求选择波段）
#
# if __name__ == "__main__":
#     main()
import os

import numpy as np
from matplotlib import pyplot as plt
def compute_color_difference(img1, img2):
    # 确保图像形状相同
    if img1.shape != img2.shape:
        raise ValueError("Input images must have the same shape.")

    # 计算色差（欧几里得距离）
    color_diff = np.sqrt(np.sum((img1 - img2) ** 2, axis=-1))  # 计算每个像素的色差
    return color_diff
from rs_trasformer import *
name='28.npy'# md随便选了几张结果连分割图都没有，倒霉
x1=r'data\image'
x2=r'data\edge'
x3=r'data\mask'
input=os.path.join(x1,name)#4波段数据
edge=os.path.join(x2,name) #边缘线分割图
mask=os.path.join(x3,name) #地块分割图
do_band = 4
transformers=Compose([
        NDVI(r_band=2, nir_band=3),
        NDWI(g_band=1, nir_band=3),
        RandomColor(prob=0.8, alpha_range=[0.8, 1.2], beta_range=[0, 500], band_num=do_band),
        RandomSplicing(prob=0.7, direction='Vertical', band_num=do_band),
        RandomFog(prob=0.3, fog_range=[0.03, 0.56], band_num=do_band),
        RandomSharpening(prob=0.7, laplacian_mode='8-1', band_num=do_band),
        RandomBlur(prob=0.3, ksize=3, band_num=do_band),
        RandomStrip(prob=0.2, strip_rate=0.05, direction='Horizontal', band_num=do_band),
        RandomFlip(prob=0.7, direction='Horizontal'),
        RandomRotate(prob=0.8, ig_pix=0),
        RandomEnlarge(prob=0.6, min_clip_rate=[0.7, 0.7]),
        RandomNarrow(prob=0.5, min_size_rate=[0.5, 0.5], ig_pix=0),
        Normalize(mean=([0] * do_band), std=([1] * do_band), bit_num=16, band_num=do_band),
        RandomRemoveBand(prob=0.3, keep_bands=[1, 2, 3], kill_bands=None),
        Resize(target_size=512, interp='NEAREST')
     ])
x=transformers(input,edge,mask)
print(x[0].shape)
def show_bands(data, bands):
    num_bands = len(bands)
    plt.figure(figsize=(15, 5))

    for i, band in enumerate(bands):
        plt.subplot(1, num_bands, i + 1)
        plt.imshow(data[:, :, band], cmap='gray')
        plt.axis('off')
        plt.title(f'Band {band + 1}')  # +1 因为通常波段从1开始

    plt.tight_layout()
    plt.show()

# 显示前六个波段
show_bands(x[0], bands=[0, 1, 2, 3, 4, 5])
